package com.jjpro.controller.lock;


import com.jjpro.annotation.SystemControllerLog;
import com.jjpro.controller.BaseController;
import com.jjpro.entity.lock.*;
import com.jjpro.requestservice.LockRequestService;
import com.jjpro.utils.AppletResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping
public class LockController extends BaseController{

    @Autowired
    private LockRequestService lockRequestService;

    private static final Logger LOGGER = LoggerFactory.getLogger(LockController.class);

    @SystemControllerLog(funcionExplain = "查看锁信息")
    @PostMapping(value = "/get/lockInfo")
    public AppletResult getLockInfo(HttpServletRequest request,
                                    @RequestBody GetLockInfoRequest getLockInfoRequest){
        getLockInfoRequest = (GetLockInfoRequest) headUtil.getAllReqHead(request,getLockInfoRequest);
        return lockRequestService.getLockInfoRequest(getLockInfoRequest);
    }

    @SystemControllerLog(funcionExplain = "绑定锁信息")
    @PostMapping(value = "/binding/lock")
    public AppletResult bindingLock(HttpServletRequest request,
                                    @RequestBody BindingLockRequest bindingLockRequest){
        bindingLockRequest = (BindingLockRequest) headUtil.getAllReqHead(request,bindingLockRequest);
        return lockRequestService.bindingLock(bindingLockRequest);
    }

    @SystemControllerLog(funcionExplain = "获取锁信息列表")
    @PostMapping(value = "/get/lockInfos")
    public AppletResult getLockInfos(HttpServletRequest request,
                                    @RequestBody GetLockInfosRequest getLockInfosRequest){
        getLockInfosRequest = (GetLockInfosRequest) headUtil.getAllReqHead(request,getLockInfosRequest);
        return lockRequestService.getLockInfos(getLockInfosRequest);
    }

    @SystemControllerLog(funcionExplain = "锁重命名")
    @PostMapping(value = "/rename/lock")
    public AppletResult renameLock(HttpServletRequest request,
                                   @RequestBody RenameLockRequest renameLockRequest){
        renameLockRequest = (RenameLockRequest) headUtil.getAllReqHead(request,renameLockRequest);
        return lockRequestService.renameLock(renameLockRequest);
    }

    @SystemControllerLog(funcionExplain = "解绑锁")
    @PostMapping(value = "/remove/lock")
    public AppletResult removeLock(HttpServletRequest request,
                                   @RequestBody RemoveLockRequest removeLockRequest){
        removeLockRequest = (RemoveLockRequest) headUtil.getAllReqHead(request,removeLockRequest);
        return lockRequestService.removeLock(removeLockRequest);
    }
}
